package cn.iocoder.yudao.module.promotion.service.interviewlog;

import cn.iocoder.yudao.module.promotion.controller.admin.interviewlog.vo.InterviewLogCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.interviewlog.vo.InterviewLogExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.interviewlog.vo.InterviewLogPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.interviewlog.vo.InterviewLogUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.interviewlog.InterviewLogConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.interviewlog.InterviewLogDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.interviewlog.InterviewLogMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.INTERVIEW_LOG_NOT_EXISTS;

/**
 * url访问记录 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class InterviewLogServiceImpl implements InterviewLogService {

    @Resource
    private InterviewLogMapper interviewLogMapper;

    @Override
    public Long createInterviewLog(InterviewLogCreateReqVO createReqVO) {
        // 插入
        InterviewLogDO interviewLog = InterviewLogConvert.INSTANCE.convert(createReqVO);
        interviewLogMapper.insert(interviewLog);
        // 返回
        return interviewLog.getId();
    }

    @Override
    public void updateInterviewLog(InterviewLogUpdateReqVO updateReqVO) {
        // 校验存在
        validateInterviewLogExists(updateReqVO.getId());
        // 更新
        InterviewLogDO updateObj = InterviewLogConvert.INSTANCE.convert(updateReqVO);
        interviewLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteInterviewLog(Long id) {
        // 校验存在
        validateInterviewLogExists(id);
        // 删除
        interviewLogMapper.deleteById(id);
    }

    private void validateInterviewLogExists(Long id) {
        if (interviewLogMapper.selectById(id) == null) {
            throw exception(INTERVIEW_LOG_NOT_EXISTS);
        }
    }

    @Override
    public InterviewLogDO getInterviewLog(Long id) {
        return interviewLogMapper.selectById(id);
    }

    @Override
    public List<InterviewLogDO> getInterviewLogList(Collection<Long> ids) {
        return interviewLogMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<InterviewLogDO> getInterviewLogPage(InterviewLogPageReqVO pageReqVO) {
        return interviewLogMapper.selectPage(pageReqVO);
    }

    @Override
    public List<InterviewLogDO> getInterviewLogList(InterviewLogExportReqVO exportReqVO) {
        return interviewLogMapper.selectList(exportReqVO);
    }

}
